import {myFetch} from '@/assets/js/utils'

export default{
    // 获取商品分类
    async getCategories () {
        const data = await myFetch({
            name: 'shopping.sys.category.info'
        })
        return data
    },
    // 获取分类下商品列表 page为0时获取分类下全部商品
    async getGoodsList ({classAppendId, classId, page}) {
        const data = await myFetch({
            name: 'shopping.sys.catagory.goods',
            class_append_id: classAppendId,
            class_id: classId,
            type: 1,
            page
        })
        return data
    },
    // 搜索商品
    async search ({search, page}) {
        const data = await myFetch({
            name: 'shopping.sys.search.goods',
            search,
            type: 1,
            page
        })
        return data
    },
    // 获取商品详情
    async getGoodsDetail (preGoodsId) {
        const data = await myFetch({
            name: 'shopping.sys.goods.info',
            pre_goods_id: preGoodsId
        })
        return data
    },
    // 获取商品图片信息
    async getGoodsDetailPic (preGoodsId) {
        const data = await myFetch({
            name: 'shopping.sys.goods.detail.pic',
            pre_goods_id: preGoodsId
        })
        return data
    },
    // 获取商品额外属性
    async getGoodsAttrs (preGoodsId) {
        const data = await myFetch({
            name: 'shopping.sys.goods.attribute',
            pre_goods_id: preGoodsId
        })
        return data
    },
    // 获取商品额外属性可提供搭配
    async getGoodsAttrsMatch (preGoodsId) {
        const data = await myFetch({
            name: 'shopping.sys.AllAvailableAttribute',
            pre_goods_id: preGoodsId
        })
        return data
    },
    // 选择额外属性 获取商品goodsId及其价格存货
    async getGoodsId ({preGoodsId, attrIds}) {
        const data = await myFetch({
            name: 'shopping.sys.goods.detail',
            pre_goods_id: preGoodsId,
            attribute: attrIds
        })
        return data
    },
    // 获取商品评论
    async getGoodsComments ({preGoodsId, type, page}) {
        const data = await myFetch({
            name: 'shopping.sys.goods.comment',
            pre_goods_id: preGoodsId,
            type,
            page
        })
        return data
    },
    // 底下和user相关
    // 收藏商品
    async collectGoods (goodsId) {
        const data = await myFetch({
            name: 'shopping.sys.collect',
            for_id: goodsId,
            for_type: 'pre_goods'
        })
        return data
    },
    // 取消收藏
    async uncollectGoods (preGoodsId) {
        const data = await myFetch({
            name: 'shopping.sys.collect.cancel',
            for_id: preGoodsId,
            for_type: 'pre_goods'
        })
        return data
    },
    // 获取收藏列表
    async getCollection (page) {
        const data = await myFetch({
            name: 'shopping.sys.collect.list',
            for_type: 'pre_goods',
            user_id: 0,
            page
        })
        return data
    },
    // 以下为秒杀部分
    // 获取现在的秒杀列表
    async getLimitedGoods () {
        const data = await myFetch({
            name: 'shopping.sys.limited.currentList'
        })
        return data
    },
    // 获取预告的秒杀列表
    async getPreviewLimitedGoods () {
        const data = await myFetch({
            name: 'shopping.sys.limited.goodsList'
        })
        return data
    },
    // 判断商品是否在秒杀时间内
    // 返回的code:158表示还未开抢 code:159表示时间已过
    async checkGoodsAvailable (preGoodsId) {
        const data = await myFetch({
            name: 'shopping.sys.timeIsUp',
            pre_goods_id: preGoodsId
        })
        return data
    }
}
